package com.gengzp.ops.controller;

import com.gengzp.common.model.base.resp.Result;
import com.gengzp.ops.service.IGatewayService;
import com.gengzp.permission.annotations.AuthIgnore;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.gengzp.common.constants.HttpStatusCodeConstants.SERVER_ERROR_CODE;

/**
 * @ClassName GatewayController
 * @Description 网关模块控制层接口
 * @Author gengzp
 * @Date 2025/6/1 18:20
 */
@RestController
@RequestMapping("/gzp")
public class GatewayController {

    private static final Logger logger = LoggerFactory.getLogger(GatewayController.class);

    @Autowired
    private IGatewayService gatewayService;

    /**
     * 统一请求入口
     */
    @AuthIgnore
    @RequestMapping("/**")
    public Result<?> unifiedRequestEntrance(HttpServletRequest request, HttpServletResponse response) {
        try {
            return gatewayService.forwardingRequest(request, response);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return Result.getFailResult(SERVER_ERROR_CODE, String.format("网关异常, %s", e.getMessage()));
        }
    }

}
